package com.sgb.packers.viewmodel;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;

import com.sgb.net.entity.ListResponse;
import com.sgb.packers.api.PackersNet;
import com.sgb.packers.entity.ProjectEntity;
import com.swgk.core.base.api.ICallBack;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.common.base.BaseViewModel;
import com.swgk.core.common.base.TeamViewModel;
import com.swgk.core.interfaces.IView;

import org.jetbrains.annotations.NotNull;

import java.util.List;
import java.util.Map;

/**
 * @author younghow
 * @date 2021/11/12
 * description:个人记工主页的ViewModel
 */
public class AddProjectViewModel extends TeamViewModel<IView> {

    public MutableLiveData<List<ProjectEntity>> mGetProjectLiveData = new MutableLiveData<>();
    public MutableLiveData<Boolean> mAddProjectLiveData = new MutableLiveData<>();

    public AddProjectViewModel(@NonNull @NotNull Application application) {
        super(application);
    }

    public void getProject(Map<String,Object> map){
        iView.loading();
        PackersNet.getInstance().getService().getProject(map).enqueue(new ICallBack<BaseEntity<ListResponse<List<ProjectEntity>>>>() {
            @Override
            public void onSuccess(BaseEntity<ListResponse<List<ProjectEntity>>> data) {
                mGetProjectLiveData.postValue(data.getData().getList());
            }
        });
    }

    public void addProject(Map<String,Object> map){
        iView.loading();
        PackersNet.getInstance().getService().addProject(map).enqueue(new ICallBack<BaseEntity>() {
            @Override
            public void onSuccess(BaseEntity data) {
                mAddProjectLiveData.postValue(true);
            }
        });
    }
}